<?php
// +----------------------------------------------------------------------
// | @filename RoleController.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-29 17:36:01
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Controllers;


use Addons\Backend\Http\Requests\Role\AssignPermissionsRequest;
use Addons\Backend\Http\Requests\Role\CreateRoleRequest;
use Addons\Backend\Http\Requests\Role\UpdateRoleRequest;
use Addons\Backend\Logics\RoleLogic;
use Illuminate\Http\Request;

class RoleController extends BaseController
{
    protected $roleLogic;

    public function __construct(RoleLogic $roleLogic)
    {
        $this->roleLogic = $roleLogic;
    }

    /**
     * 角色列表
     * @param Request $request
     * @return mixed
     */
    public function list(Request $request)
    {
        $res = $this->roleLogic->list($request->input());
        return $this->respond($res);
    }

    /**
     * 所有角色
     */
    public function all()
    {
        $res = $this->roleLogic->all();
        return $this->respond($res);
    }

    /**
     * 创建角色
     * @param CreateRoleRequest $request
     * @return mixed
     */
    public function create(CreateRoleRequest $request)
    {
        $res = $this->roleLogic->create($request->validated());
        return $this->respond($res);
    }

    /**
     * 编辑角色
     * @param UpdateRoleRequest $request
     * @return mixed
     */
    public function update(UpdateRoleRequest $request)
    {
        $res = $this->roleLogic->update($request->validated());
        return $this->respond($res);
    }

    /**
     * 删除角色
     * @param $id
     * @return mixed
     */
    public function delete($id)
    {
        $res = $this->roleLogic->delete($id);
        return $this->respond($res);
    }

    /**
     * 给角色分配权限
     * @param AssignPermissionsRequest $request
     * @return mixed
     */
    public function assignPermissions(AssignPermissionsRequest $request)
    {
        $res = $this->roleLogic->assignPermissions($request->validated());
        return $this->respond($res);
    }

}
